
# 演示标准使用方法

import numpy as np
from mpl_toolkits import mplot3d # matplotlib的三维模块
import matplotlib.pyplot as plt

# 创建画布
plt.rcParams["font.sans-serif"]=["SimHei"]  # 设置字体
plt.rcParams["axes.unicode_minus"]=False    # “-”负号的显示
fig = plt.figure()                          # 空的画布
ax = fig.add_subplot(111, projection='3d')  # 创建3d绘图区域
ax.tick_params(labelsize=8)                 # 刻度字体

# 三维数据
z = np.linspace(0, 1, 100)
x = z * np.sin(20 * z)
y = z * np.cos(20 * z)
s = z * 200

# 绘图
ax.scatter3D(x, y, z, s = s)     # 绘制（散点图）
ax.set_title('3D 点')            # 标题

# 参考线
def axs(xx=(-1,1),yx=(-1,1),zx=(-1,1)): 
    color = ['r', 'g', 'b']
    for i,t in  enumerate((xx, yx, zx)):
        xs = [(0,0), (0,0), (0,0)]
        f = True if t[0]<0 and t[1]>0 else False
        if f:
            xs[i] = (t[0], 0)
            ax.plot(xs[0], xs[1], xs[2], linestyle=':', color=color[i])
            xs[i] = (0, t[1])
            ax.plot(xs[0], xs[1], xs[2], linestyle='-', color=color[i])
        else: 
            xs[i] = (t[0], t[1])
            ax.plot(xs[0], xs[1], xs[2], linestyle='-', color=color[i])
axs(zx=(0,1))
ax.grid(b=None)                  # 隐藏网格

# 显示窗口
plt.show()